package camid.util.monitoring;


public class NodeEvaluator {

	private MetricEvaluator responseTimeEvaluator;
	
	private MetricEvaluator cpuEvaluator;
	
	private MetricEvaluator memEvaluator;
	
	private MetricEvaluator numberOfObjectsEvaluator;
	
	private MetricEvaluator throughputEvaluator;
	
	public Double feedMetric(NodeMetrics nodeMetrics) {
		
		double rtCost = responseTimeEvaluator.evaluateCostFromMetric(nodeMetrics.getNodeResponseTime());
//		double inverseTp = 1 / nodeMetrics.getNodeThroughput();
//		inverseTp = inverseTp == Double.NaN ? 0.0 : inverseTp; 
//		double tpCost = throughputEvaluator.evalateMetricFromCost( inverseTp );
//		double cpuCost = cpuEvaluator.evaluateCostFromMetric(nodeMetrics.getCpuUsage());
//		double memCost = memEvaluator.evaluateCostFromMetric(nodeMetrics.getMemoryUsage());
//		double nobjCost = numberOfObjectsEvaluator.evaluateCostFromMetric(nodeMetrics.getNumberOfObjects());
		
		
		double weightTotal = responseTimeEvaluator.getWeight()
//							  + throughputEvaluator.getWeight()
//							  + numberOfObjectsEvaluator.getWeight()
//							  + cpuEvaluator.getWeight()
//							  + memEvaluator.getWeight()
		; //end weight calculation.
		
		
		double nodeCost = (
				rtCost 
//				+ tpCost + nobjCost 
//				+ cpuCost + memCost 
				) / weightTotal;
		
		return nodeCost;
	}

	public void setNumberOfObjectsWeight(Double numObjectsWeight) 
	{
		numberOfObjectsEvaluator = new MetricEvaluator("NO", numObjectsWeight);	
	}

	public void setResponseTimeWeight(Double responseTimeWeight) 
	{
		responseTimeEvaluator = new MetricEvaluator("RT", responseTimeWeight);	
	}
	
	public void setThroughputWeight(Double throughputWeight)
	{
		throughputEvaluator = new MetricEvaluator("TP", throughputWeight);
	}

	public void setCPUWeight(Double cpuWeight) 
	{
		cpuEvaluator = new MetricEvaluator("CPU", cpuWeight, 0, 1);
	}
	
	public void setMemWeight(Double memWeight) 
	{
		memEvaluator = new MetricEvaluator("MEM", memWeight, 0, 100);
	}

	public double numberOfObjectsFromCost(double cost) 
	{	
		double nobj = numberOfObjectsEvaluator.evalateMetricFromCost(cost);
		return nobj;
	}

}
